package com.shujia.jdbc;

import java.sql.*;

/*
    1、注册驱动
    2、获取连接对象
    3、创建数据库操作对象
    4、执行sql
    5、获取结果
    6、释放资源
 */
public class JDBCDemo1 {
    public static void main(String[] args) throws Exception {
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/shujia");
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("select * from students2 limit 10");
        while (rs.next()) {
            int id = rs.getInt(1);
            String name = rs.getString(2);
            int age = rs.getInt(3);
            String gender = rs.getString(4);
            String clazz = rs.getString(5);
            System.out.println(id + "," + name + "," + age + "," + gender + "," + clazz);
        }
        rs.close();
        stat.close();
        conn.close();
    }
}
